package 力扣_数学思维题;

/**303. 区域和检索 - 数组不可变
 * @author zx
 * @create 2022-04-28 15:32
 */
public class 区域和检索 {
}
class NumArray {
    int[] preSums;
    public NumArray(int[] nums) {
        int n = nums.length;
        preSums = new int[n];
        preSums[0] = nums[0];
        for(int i = 1;i < n;i++){
            preSums[i] = preSums[i - 1] + nums[i];
        }
    }

    public int sumRange(int left, int right) {
        if(left == 0){
            return preSums[right];
        }
        return preSums[right] - preSums[left - 1];
    }
}